package keeto.com.vn.bms.network.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.GetUserInfoRequest;
import keeto.com.vn.bms.network.response.GetUserInfoResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskGetUserInfo extends AbstractTask {
String mAuthkey;
	
	public TaskGetUserInfo(BMSListener listener, IBMSCore core, String authkey) {
		super(listener, core);
		// TODO Auto-generated constructor stub
		this.mAuthkey = authkey;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		GetUserInfoRequest request = new GetUserInfoRequest();
		request.setAuthKey(mAuthkey);
		GetUserInfoResponse response = protocol.getUserInfo(request);
		
		for (BMSListener mlistener : listener){
			mlistener.finishGetUserInfo(response.getReturnCode(), response.getUserModel());
		}
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for (BMSListener mlistener : listener){
			mlistener.finishGetUserInfo(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, null);
		}
	}

}
